<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/**
<span class='line'>  2</span>  * Constructs a new, empty network layout. Layouts are not typically constructed
<span class='line'>  3</span>  * directly; instead, they are added to an existing panel via
<span class='line'>  4</span>  * {@link pv.Mark#add}.
<span class='line'>  5</span>  *
<span class='line'>  6</span>  * @class Represents an abstract layout for network diagrams. This class
<span class='line'>  7</span>  * provides the basic structure for both node-link diagrams (such as
<span class='line'>  8</span>  * force-directed graph layout) and space-filling network diagrams (such as
<span class='line'>  9</span>  * sunbursts and treemaps). Note that "network" here is a general term that
<span class='line'> 10</span>  * includes hierarchical structures; a tree is represented using links from
<span class='line'> 11</span>  * child to parent.
<span class='line'> 12</span>  *
<span class='line'> 13</span>  * &lt;p>Network layouts require the graph data structure to be defined using two
<span class='line'> 14</span>  * properties:&lt;ul>
<span class='line'> 15</span>  *
<span class='line'> 16</span>  * &lt;li>&lt;tt>nodes&lt;/tt> - an array of objects representing nodes. Objects in this
<span class='line'> 17</span>  * array must conform to the {@link pv.Layout.Network.Node} interface; which is
<span class='line'> 18</span>  * to say, be careful to avoid naming collisions with automatic attributes such
<span class='line'> 19</span>  * as &lt;tt>index&lt;/tt> and &lt;tt>linkDegree&lt;/tt>. If the nodes property is defined
<span class='line'> 20</span>  * as an array of primitives, such as numbers or strings, these primitives are
<span class='line'> 21</span>  * automatically wrapped in an object; the resulting object's &lt;tt>nodeValue&lt;/tt>
<span class='line'> 22</span>  * attribute points to the original primitive value.
<span class='line'> 23</span>  *
<span class='line'> 24</span>  * &lt;p>&lt;li>&lt;tt>links&lt;/tt> - an array of objects representing links. Objects in
<span class='line'> 25</span>  * this array must conform to the {@link pv.Layout.Network.Link} interface; at a
<span class='line'> 26</span>  * minimum, either &lt;tt>source&lt;/tt> and &lt;tt>target&lt;/tt> indexes or
<span class='line'> 27</span>  * &lt;tt>sourceNode&lt;/tt> and &lt;tt>targetNode&lt;/tt> references must be set. Note that
<span class='line'> 28</span>  * if the links property is defined after the nodes property, the links can be
<span class='line'> 29</span>  * defined in terms of &lt;tt>this.nodes()&lt;/tt>.
<span class='line'> 30</span>  *
<span class='line'> 31</span>  * &lt;/ul>
<span class='line'> 32</span>  *
<span class='line'> 33</span>  * &lt;p>Three standard mark prototypes are provided:&lt;ul>
<span class='line'> 34</span>  *
<span class='line'> 35</span>  * &lt;li>&lt;tt>node&lt;/tt> - for rendering nodes; typically a {@link pv.Dot}. The node
<span class='line'> 36</span>  * mark is added directly to the layout, with the data property defined via the
<span class='line'> 37</span>  * layout's &lt;tt>nodes&lt;/tt> property. Properties such as &lt;tt>strokeStyle&lt;/tt> and
<span class='line'> 38</span>  * &lt;tt>fillStyle&lt;/tt> can be overridden to compute properties from node data
<span class='line'> 39</span>  * dynamically.
<span class='line'> 40</span>  *
<span class='line'> 41</span>  * &lt;p>&lt;li>&lt;tt>link&lt;/tt> - for rendering links; typically a {@link pv.Line}. The
<span class='line'> 42</span>  * link mark is added to a child panel, whose data property is defined as
<span class='line'> 43</span>  * layout's &lt;tt>links&lt;/tt> property. The link's data property is then a
<span class='line'> 44</span>  * two-element array of the source node and target node. Thus, poperties such as
<span class='line'> 45</span>  * &lt;tt>strokeStyle&lt;/tt> and &lt;tt>fillStyle&lt;/tt> can be overridden to compute
<span class='line'> 46</span>  * properties from either the node data (the first argument) or the link data
<span class='line'> 47</span>  * (the second argument; the parent panel data) dynamically.
<span class='line'> 48</span>  *
<span class='line'> 49</span>  * &lt;p>&lt;li>&lt;tt>label&lt;/tt> - for rendering node labels; typically a
<span class='line'> 50</span>  * {@link pv.Label}. The label mark is added directly to the layout, with the
<span class='line'> 51</span>  * data property defined via the layout's &lt;tt>nodes&lt;/tt> property. Properties
<span class='line'> 52</span>  * such as &lt;tt>strokeStyle&lt;/tt> and &lt;tt>fillStyle&lt;/tt> can be overridden to
<span class='line'> 53</span>  * compute properties from node data dynamically.
<span class='line'> 54</span>  *
<span class='line'> 55</span>  * &lt;/ul>Note that some network implementations may not support all three
<span class='line'> 56</span>  * standard mark prototypes; for example, space-filling hierarchical layouts
<span class='line'> 57</span>  * typically do not use a &lt;tt>link&lt;/tt> prototype, as the parent-child links are
<span class='line'> 58</span>  * implied by the structure of the space-filling &lt;tt>node&lt;/tt> marks.  Check the
<span class='line'> 59</span>  * specific network layout for implementation details.
<span class='line'> 60</span>  *
<span class='line'> 61</span>  * &lt;p>Network layout properties, including &lt;tt>nodes&lt;/tt> and &lt;tt>links&lt;/tt>,
<span class='line'> 62</span>  * are typically cached rather than re-evaluated with every call to render. This
<span class='line'> 63</span>  * is a performance optimization, as network layout algorithms can be
<span class='line'> 64</span>  * expensive. If the network structure changes, call {@link #reset} to clear the
<span class='line'> 65</span>  * cache before rendering. Note that although the network layout properties are
<span class='line'> 66</span>  * cached, child mark properties, such as the marks used to render the nodes and
<span class='line'> 67</span>  * links, &lt;i>are not&lt;/i>. Therefore, non-structural changes to the network
<span class='line'> 68</span>  * layout, such as changing the color of a mark on mouseover, do not need to
<span class='line'> 69</span>  * reset the layout.
<span class='line'> 70</span>  *
<span class='line'> 71</span>  * @see pv.Layout.Hierarchy
<span class='line'> 72</span>  * @see pv.Layout.Force
<span class='line'> 73</span>  * @see pv.Layout.Matrix
<span class='line'> 74</span>  * @see pv.Layout.Arc
<span class='line'> 75</span>  * @see pv.Layout.Rollup
<span class='line'> 76</span>  * @extends pv.Layout
<span class='line'> 77</span>  */</span><span class="WHIT">
<span class='line'> 78</span> </span><span class="NAME">pv.Layout.Network</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 79</span> </span><span class="WHIT">  </span><span class="NAME">pv.Layout.call</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 80</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">that</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 81</span> 
<span class='line'> 82</span> </span><span class="WHIT">  </span><span class="COMM">/* @private Version tracking to cache layout state, improving performance. */</span><span class="WHIT">
<span class='line'> 83</span> </span><span class="WHIT">  </span><span class="NAME">this.$id</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pv.id</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 84</span> 
<span class='line'> 85</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 86</span>    * The node prototype. This prototype is intended to be used with a Dot mark
<span class='line'> 87</span>    * in conjunction with the link prototype.
<span class='line'> 88</span>    *
<span class='line'> 89</span>    * @type pv.Mark
<span class='line'> 90</span>    * @name pv.Layout.Network.prototype.node
<span class='line'> 91</span>    */</span><span class="WHIT">
<span class='line'> 92</span> </span><span class="WHIT">  </span><span class="PUNC">(</span><span class="NAME">this.node</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">pv.Mark</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 93</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">data</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">that.nodes</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 94</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">strokeStyle</span><span class="PUNC">(</span><span class="STRN">"#1f77b4"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 95</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">fillStyle</span><span class="PUNC">(</span><span class="STRN">"#fff"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 96</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">left</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">n</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">n.x</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 97</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">top</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">n</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">n.y</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">parent</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 98</span> 
<span class='line'> 99</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>100</span>    * The link prototype, which renders edges between source nodes and target
<span class='line'>101</span>    * nodes. This prototype is intended to be used with a Line mark in
<span class='line'>102</span>    * conjunction with the node prototype.
<span class='line'>103</span>    *
<span class='line'>104</span>    * @type pv.Mark
<span class='line'>105</span>    * @name pv.Layout.Network.prototype.link
<span class='line'>106</span>    */</span><span class="WHIT">
<span class='line'>107</span> </span><span class="WHIT">  </span><span class="NAME">this.link</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">pv.Mark</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>108</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">extend</span><span class="PUNC">(</span><span class="NAME">this.node</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>109</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">data</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">p</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="NAME">p.sourceNode</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">p.targetNode</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>110</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">fillStyle</span><span class="PUNC">(</span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>111</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">lineWidth</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">d</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">p</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">p.linkValue</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NUMB">1.5</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>112</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">strokeStyle</span><span class="PUNC">(</span><span class="STRN">"rgba(0,0,0,.2)"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>113</span> 
<span class='line'>114</span> </span><span class="WHIT">  </span><span class="NAME">this.link.add</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">type</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>115</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">that.add</span><span class="PUNC">(</span><span class="NAME">pv.Panel</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>116</span> </span><span class="WHIT">        </span><span class="PUNC">.</span><span class="NAME">data</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">that.links</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>117</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">add</span><span class="PUNC">(</span><span class="NAME">type</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>118</span> </span><span class="WHIT">        </span><span class="PUNC">.</span><span class="NAME">extend</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>119</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>120</span> 
<span class='line'>121</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>122</span>    * The node label prototype, which renders the node name adjacent to the node.
<span class='line'>123</span>    * This prototype is provided as an alternative to using the anchor on the
<span class='line'>124</span>    * node mark; it is primarily intended to be used with radial node-link
<span class='line'>125</span>    * layouts, since it provides a convenient mechanism to set the text angle.
<span class='line'>126</span>    *
<span class='line'>127</span>    * @type pv.Mark
<span class='line'>128</span>    * @name pv.Layout.Network.prototype.label
<span class='line'>129</span>    */</span><span class="WHIT">
<span class='line'>130</span> </span><span class="WHIT">  </span><span class="PUNC">(</span><span class="NAME">this.label</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">pv.Mark</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>131</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">extend</span><span class="PUNC">(</span><span class="NAME">this.node</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>132</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">textMargin</span><span class="PUNC">(</span><span class="NUMB">7</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>133</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">textBaseline</span><span class="PUNC">(</span><span class="STRN">"middle"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>134</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">text</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">n</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">n.nodeName</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">n.nodeValue</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>135</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">textAngle</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">n</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>136</span> </span><span class="WHIT">          </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">a</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">n.midAngle</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>137</span> </span><span class="WHIT">          </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">pv.Wedge.upright</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">a</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">a</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">Math.PI</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>138</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>139</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">textAlign</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">n</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>140</span> </span><span class="WHIT">          </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">pv.Wedge.upright</span><span class="PUNC">(</span><span class="NAME">n.midAngle</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="STRN">"left"</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">"right"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>141</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">parent</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>142</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>143</span> 
<span class='line'>144</span> </span><span class="COMM">/**
<span class='line'>145</span>  * @class Represents a node in a network layout. There is no explicit
<span class='line'>146</span>  * constructor; this class merely serves to document the attributes that are
<span class='line'>147</span>  * used on nodes in network layouts. (Note that hierarchical nodes place
<span class='line'>148</span>  * additional requirements on node representation, vis {@link pv.Dom.Node}.)
<span class='line'>149</span>  *
<span class='line'>150</span>  * @see pv.Layout.Network
<span class='line'>151</span>  * @name pv.Layout.Network.Node
<span class='line'>152</span>  */</span><span class="WHIT">
<span class='line'>153</span> 
<span class='line'>154</span> </span><span class="COMM">/**
<span class='line'>155</span>  * The node index, zero-based. This attribute is populated automatically based
<span class='line'>156</span>  * on the index in the array returned by the &lt;tt>nodes&lt;/tt> property.
<span class='line'>157</span>  *
<span class='line'>158</span>  * @type number
<span class='line'>159</span>  * @name pv.Layout.Network.Node.prototype.index
<span class='line'>160</span>  */</span><span class="WHIT">
<span class='line'>161</span> 
<span class='line'>162</span> </span><span class="COMM">/**
<span class='line'>163</span>  * The link degree; the sum of link values for all incoming and outgoing links.
<span class='line'>164</span>  * This attribute is populated automatically.
<span class='line'>165</span>  *
<span class='line'>166</span>  * @type number
<span class='line'>167</span>  * @name pv.Layout.Network.Node.prototype.linkDegree
<span class='line'>168</span>  */</span><span class="WHIT">
<span class='line'>169</span> 
<span class='line'>170</span> </span><span class="COMM">/**
<span class='line'>171</span>  * The node name; optional. If present, this attribute will be used to provide
<span class='line'>172</span>  * the text for node labels. If not present, the label text will fallback to the
<span class='line'>173</span>  * &lt;tt>nodeValue&lt;/tt> attribute.
<span class='line'>174</span>  *
<span class='line'>175</span>  * @type string
<span class='line'>176</span>  * @name pv.Layout.Network.Node.prototype.nodeName
<span class='line'>177</span>  */</span><span class="WHIT">
<span class='line'>178</span> 
<span class='line'>179</span> </span><span class="COMM">/**
<span class='line'>180</span>  * The node value; optional. If present, and no &lt;tt>nodeName&lt;/tt> attribute is
<span class='line'>181</span>  * present, the node value will be used as the label text. This attribute is
<span class='line'>182</span>  * also automatically populated if the nodes are specified as an array of
<span class='line'>183</span>  * primitives, such as strings or numbers.
<span class='line'>184</span>  *
<span class='line'>185</span>  * @type object
<span class='line'>186</span>  * @name pv.Layout.Network.Node.prototype.nodeValue
<span class='line'>187</span>  */</span><span class="WHIT">
<span class='line'>188</span> 
<span class='line'>189</span> </span><span class="COMM">/**
<span class='line'>190</span>  * @class Represents a link in a network layout. There is no explicit
<span class='line'>191</span>  * constructor; this class merely serves to document the attributes that are
<span class='line'>192</span>  * used on links in network layouts. For hierarchical layouts, this class is
<span class='line'>193</span>  * used to represent the parent-child links.
<span class='line'>194</span>  *
<span class='line'>195</span>  * @see pv.Layout.Network
<span class='line'>196</span>  * @name pv.Layout.Network.Link
<span class='line'>197</span>  */</span><span class="WHIT">
<span class='line'>198</span> 
<span class='line'>199</span> </span><span class="COMM">/**
<span class='line'>200</span>  * The link value, or weight; optional. If not specified (or not a number), the
<span class='line'>201</span>  * default value of 1 is used.
<span class='line'>202</span>  *
<span class='line'>203</span>  * @type number
<span class='line'>204</span>  * @name pv.Layout.Network.Link.prototype.linkValue
<span class='line'>205</span>  */</span><span class="WHIT">
<span class='line'>206</span> 
<span class='line'>207</span> </span><span class="COMM">/**
<span class='line'>208</span>  * The link's source node. If not set, this value will be derived from the
<span class='line'>209</span>  * &lt;tt>source&lt;/tt> attribute index.
<span class='line'>210</span>  *
<span class='line'>211</span>  * @type pv.Layout.Network.Node
<span class='line'>212</span>  * @name pv.Layout.Network.Link.prototype.sourceNode
<span class='line'>213</span>  */</span><span class="WHIT">
<span class='line'>214</span> 
<span class='line'>215</span> </span><span class="COMM">/**
<span class='line'>216</span>  * The link's target node. If not set, this value will be derived from the
<span class='line'>217</span>  * &lt;tt>target&lt;/tt> attribute index.
<span class='line'>218</span>  *
<span class='line'>219</span>  * @type pv.Layout.Network.Node
<span class='line'>220</span>  * @name pv.Layout.Network.Link.prototype.targetNode
<span class='line'>221</span>  */</span><span class="WHIT">
<span class='line'>222</span> 
<span class='line'>223</span> </span><span class="COMM">/**
<span class='line'>224</span>  * Alias for &lt;tt>sourceNode&lt;/tt>, as expressed by the index of the source node.
<span class='line'>225</span>  * This attribute is not populated automatically, but may be used as a more
<span class='line'>226</span>  * convenient identification of the link's source, for example in a static JSON
<span class='line'>227</span>  * representation.
<span class='line'>228</span>  *
<span class='line'>229</span>  * @type number
<span class='line'>230</span>  * @name pv.Layout.Network.Link.prototype.source
<span class='line'>231</span>  */</span><span class="WHIT">
<span class='line'>232</span> 
<span class='line'>233</span> </span><span class="COMM">/**
<span class='line'>234</span>  * Alias for &lt;tt>targetNode&lt;/tt>, as expressed by the index of the target node.
<span class='line'>235</span>  * This attribute is not populated automatically, but may be used as a more
<span class='line'>236</span>  * convenient identification of the link's target, for example in a static JSON
<span class='line'>237</span>  * representation.
<span class='line'>238</span>  *
<span class='line'>239</span>  * @type number
<span class='line'>240</span>  * @name pv.Layout.Network.Link.prototype.target
<span class='line'>241</span>  */</span><span class="WHIT">
<span class='line'>242</span> 
<span class='line'>243</span> </span><span class="COMM">/**
<span class='line'>244</span>  * Alias for &lt;tt>linkValue&lt;/tt>. This attribute is not populated automatically,
<span class='line'>245</span>  * but may be used instead of the &lt;tt>linkValue&lt;/tt> attribute when specifying
<span class='line'>246</span>  * links.
<span class='line'>247</span>  *
<span class='line'>248</span>  * @type number
<span class='line'>249</span>  * @name pv.Layout.Network.Link.prototype.value
<span class='line'>250</span>  */</span><span class="WHIT">
<span class='line'>251</span> 
<span class='line'>252</span> </span><span class="COMM">/** @private Transform nodes and links on cast. */</span><span class="WHIT">
<span class='line'>253</span> </span><span class="NAME">pv.Layout.Network.prototype</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pv.extend</span><span class="PUNC">(</span><span class="NAME">pv.Layout</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>254</span> </span><span class="WHIT">    </span><span class="PUNC">.</span><span class="NAME">property</span><span class="PUNC">(</span><span class="STRN">"nodes"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">v</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>255</span> </span><span class="WHIT">        </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">v.map</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">d</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>256</span> </span><span class="WHIT">            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">d</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="STRN">"object"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">d</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="NAME">nodeValue</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">d</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>257</span> </span><span class="WHIT">            </span><span class="NAME">d.index</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>258</span> </span><span class="WHIT">            </span><span class="NAME">d.linkDegree</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>259</span> </span><span class="WHIT">            </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">d</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>260</span> </span><span class="WHIT">          </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>261</span> </span><span class="WHIT">      </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>262</span> </span><span class="WHIT">    </span><span class="PUNC">.</span><span class="NAME">property</span><span class="PUNC">(</span><span class="STRN">"links"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">v</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>263</span> </span><span class="WHIT">        </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">v.map</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">d</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>264</span> </span><span class="WHIT">            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">isNaN</span><span class="PUNC">(</span><span class="NAME">d.linkValue</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">d.linkValue</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">isNaN</span><span class="PUNC">(</span><span class="NAME">d.value</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">d.value</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>265</span> </span><span class="WHIT">            </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">d</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>266</span> </span><span class="WHIT">          </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>267</span> </span><span class="WHIT">      </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>268</span> 
<span class='line'>269</span> </span><span class="COMM">/**
<span class='line'>270</span>  * Resets the cache, such that changes to layout property definitions will be
<span class='line'>271</span>  * visible on subsequent render. Unlike normal marks (and normal layouts),
<span class='line'>272</span>  * properties associated with network layouts are not automatically re-evaluated
<span class='line'>273</span>  * on render; the properties are cached, and any expensive layout algorithms are
<span class='line'>274</span>  * only run after the layout is explicitly reset.
<span class='line'>275</span>  *
<span class='line'>276</span>  * @returns {pv.Layout.Network} this.
<span class='line'>277</span>  */</span><span class="WHIT">
<span class='line'>278</span> </span><span class="NAME">pv.Layout.Network.prototype.reset</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>279</span> </span><span class="WHIT">  </span><span class="NAME">this.$id</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pv.id</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>280</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>281</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>282</span> 
<span class='line'>283</span> </span><span class="COMM">/** @private Skip evaluating properties if cached. */</span><span class="WHIT">
<span class='line'>284</span> </span><span class="NAME">pv.Layout.Network.prototype.buildProperties</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">properties</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>285</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">s.$id</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">this.$id</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>286</span> </span><span class="WHIT">    </span><span class="NAME">pv.Layout.prototype.buildProperties.call</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">properties</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>287</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>288</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>289</span> 
<span class='line'>290</span> </span><span class="COMM">/** @private Compute link degrees; map source and target indexes to nodes. */</span><span class="WHIT">
<span class='line'>291</span> </span><span class="NAME">pv.Layout.Network.prototype.buildImplied</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>292</span> </span><span class="WHIT">  </span><span class="NAME">pv.Layout.prototype.buildImplied.call</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>293</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">s.$id</span><span class="WHIT"> </span><span class="PUNC">>=</span><span class="WHIT"> </span><span class="NAME">this.$id</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>294</span> </span><span class="WHIT">  </span><span class="NAME">s.$id</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.$id</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>295</span> </span><span class="WHIT">  </span><span class="NAME">s.links.forEach</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">d</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>296</span> </span><span class="WHIT">      </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">v</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">d.linkValue</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>297</span> </span><span class="WHIT">      </span><span class="PUNC">(</span><span class="NAME">d.sourceNode</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">d.sourceNode</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.nodes</span><span class="PUNC">[</span><span class="NAME">d.source</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">linkDegree</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">v</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>298</span> </span><span class="WHIT">      </span><span class="PUNC">(</span><span class="NAME">d.targetNode</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">d.targetNode</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.nodes</span><span class="PUNC">[</span><span class="NAME">d.target</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">linkDegree</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">v</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>299</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>300</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>301</span> </span></pre></body></html>